{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate Well Trajectory from Different Data Sources\n", "\n", "This notebook shows examples of how to calculate the well trajectory from different data sources.\n", "Currently accepting data from CSV, dataframe, dictionary, and json.\n", "\n", "The data from csv and dataframe must be in a certain format commonly seen in directional surveys.\n", "The dictionary and json must be in a format specific to the library." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from welltrajconvert.wellbore_trajectory import *\n", "from welltrajconvert.data_source import *" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get Wellbore Trajectory object" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "path = './'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`get_files` is a great function for accessing your data in a folder. You can access all data in a specific folder or data with a specific extension. It returns said data in a list of items." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[WindowsPath('data/wellbore_survey.csv'),\n", " WindowsPath('data/wellbore_survey.json'),\n", " WindowsPath('data/wellbore_survey_many.csv'),\n", " WindowsPath('data/well_export.json')]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# use get_files to get all the files in the data directory\n", "file_paths = get_files(path, folders='data')\n", "#gives a path lib path to all your files in the folder of choice\n", "file_paths.items" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## From Dict" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dict_keys(['wellId', 'md', 'inc', 'azim', 'surface_latitude', 'surface_longitude'])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "json_path = get_files(path, folders='data', extensions='.json')\n", "json_path.items[0]\n", "\n", "with open(json_path.items[0]) as json_file:\n", " json_data = json.load(json_file)\n", "json_file.close()\n", "#show the dict keys present in the dict.\n", "json_data.keys()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimtvde_w_deviationn_s_deviationdlssurface_latitudesurface_longitudelongitude_pointslatitude_pointszone_numberzone_letterx_pointsy_pointssurface_xsurface_yisHorizontal
0well_C0.000.00227.110.0000000.000000e+000.000000e+000.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
1well_C35.000.00227.1135.000000-1.484001e-17-1.378531e-170.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
2well_C774.810.46227.11774.802052-2.175842e+00-2.021203e+000.06217829.90829447.68852147.68851429.90828938R759587.2712433.311661e+06759587.934443.311662e+06Vertical
3well_C800.000.13163.86799.991684-2.241984e+00-2.117474e+001.31232329.90829447.68852147.68851429.90828938R759587.2510833.311661e+06759587.934443.311662e+06Vertical
4well_C900.000.57230.43899.989571-2.593878e+00-2.543311e+000.43922129.90829447.68852147.68851229.90828838R759587.1438263.311661e+06759587.934443.311662e+06Vertical
\n", "
" ], "text/plain": [ " wellId md inc azim tvd e_w_deviation n_s_deviation \\\n", "0 well_C 0.00 0.00 227.11 0.000000 0.000000e+00 0.000000e+00 \n", "1 well_C 35.00 0.00 227.11 35.000000 -1.484001e-17 -1.378531e-17 \n", "2 well_C 774.81 0.46 227.11 774.802052 -2.175842e+00 -2.021203e+00 \n", "3 well_C 800.00 0.13 163.86 799.991684 -2.241984e+00 -2.117474e+00 \n", "4 well_C 900.00 0.57 230.43 899.989571 -2.593878e+00 -2.543311e+00 \n", "\n", " dls surface_latitude surface_longitude longitude_points \\\n", "0 0.000000 29.908294 47.688521 47.688521 \n", "1 0.000000 29.908294 47.688521 47.688521 \n", "2 0.062178 29.908294 47.688521 47.688514 \n", "3 1.312323 29.908294 47.688521 47.688514 \n", "4 0.439221 29.908294 47.688521 47.688512 \n", "\n", " latitude_points zone_number zone_letter x_points y_points \\\n", "0 29.908294 38 R 759587.934440 3.311662e+06 \n", "1 29.908294 38 R 759587.934440 3.311662e+06 \n", "2 29.908289 38 R 759587.271243 3.311661e+06 \n", "3 29.908289 38 R 759587.251083 3.311661e+06 \n", "4 29.908288 38 R 759587.143826 3.311661e+06 \n", "\n", " surface_x surface_y isHorizontal \n", "0 759587.93444 3.311662e+06 Vertical \n", "1 759587.93444 3.311662e+06 Vertical \n", "2 759587.93444 3.311662e+06 Vertical \n", "3 759587.93444 3.311662e+06 Vertical \n", "4 759587.93444 3.311662e+06 Vertical " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# call DataSource.from_dictionary and input the dict data\n", "my_data = DataSource.from_dictionary(json_data)\n", "\n", "#view the dict data dataclass object\n", "my_data.data\n", "#create a wellboreTrajectory object\n", "dev_obj = WellboreTrajectory(my_data.data)\n", "#view the object\n", "dev_obj.deviation_survey_obj\n", "#calculate the survey points along the wellbore for the object\n", "dev_obj.calculate_survey_points()\n", "#serialize the data\n", "json_ds = dev_obj.serialize()\n", "# view the json in a df\n", "json_ds_obj = json.loads(json_ds)\n", "df_min_curve = pd.DataFrame(json_ds_obj)\n", "df_min_curve.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## From DF" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you have a df and want to calculate its metadata use the following workflow. Just enter in the column names and calculate its survey points." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimsurface_latitudesurface_longitude
0well_C0.000.00227.1129.90829447.688521
1well_C35.000.00227.1129.90829447.688521
2well_C774.810.46227.1129.90829447.688521
3well_C800.000.13163.8629.90829447.688521
4well_C900.000.57230.4329.90829447.688521
\n", "
" ], "text/plain": [ " wellId md inc azim surface_latitude surface_longitude\n", "0 well_C 0.00 0.00 227.11 29.908294 47.688521\n", "1 well_C 35.00 0.00 227.11 29.908294 47.688521\n", "2 well_C 774.81 0.46 227.11 29.908294 47.688521\n", "3 well_C 800.00 0.13 163.86 29.908294 47.688521\n", "4 well_C 900.00 0.57 230.43 29.908294 47.688521" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# FROM DF\n", "csv_path = get_files(path, folders='data', extensions='.csv')\n", "csv_path.items[0]\n", "\n", "df = pd.read_csv(csv_path.items[0],sep=',')\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimtvde_w_deviationn_s_deviationdlssurface_latitudesurface_longitudelongitude_pointslatitude_pointszone_numberzone_letterx_pointsy_pointssurface_xsurface_yisHorizontal
0well_C0.000.00227.110.0000000.000000e+000.000000e+000.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
1well_C35.000.00227.1135.000000-1.484001e-17-1.378531e-170.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
2well_C774.810.46227.11774.802052-2.175842e+00-2.021203e+000.06217829.90829447.68852147.68851429.90828938R759587.2712433.311661e+06759587.934443.311662e+06Vertical
3well_C800.000.13163.86799.991684-2.241984e+00-2.117474e+001.31232329.90829447.68852147.68851429.90828938R759587.2510833.311661e+06759587.934443.311662e+06Vertical
4well_C900.000.57230.43899.989571-2.593878e+00-2.543311e+000.43922129.90829447.68852147.68851229.90828838R759587.1438263.311661e+06759587.934443.311662e+06Vertical
\n", "
" ], "text/plain": [ " wellId md inc azim tvd e_w_deviation n_s_deviation \\\n", "0 well_C 0.00 0.00 227.11 0.000000 0.000000e+00 0.000000e+00 \n", "1 well_C 35.00 0.00 227.11 35.000000 -1.484001e-17 -1.378531e-17 \n", "2 well_C 774.81 0.46 227.11 774.802052 -2.175842e+00 -2.021203e+00 \n", "3 well_C 800.00 0.13 163.86 799.991684 -2.241984e+00 -2.117474e+00 \n", "4 well_C 900.00 0.57 230.43 899.989571 -2.593878e+00 -2.543311e+00 \n", "\n", " dls surface_latitude surface_longitude longitude_points \\\n", "0 0.000000 29.908294 47.688521 47.688521 \n", "1 0.000000 29.908294 47.688521 47.688521 \n", "2 0.062178 29.908294 47.688521 47.688514 \n", "3 1.312323 29.908294 47.688521 47.688514 \n", "4 0.439221 29.908294 47.688521 47.688512 \n", "\n", " latitude_points zone_number zone_letter x_points y_points \\\n", "0 29.908294 38 R 759587.934440 3.311662e+06 \n", "1 29.908294 38 R 759587.934440 3.311662e+06 \n", "2 29.908289 38 R 759587.271243 3.311661e+06 \n", "3 29.908289 38 R 759587.251083 3.311661e+06 \n", "4 29.908288 38 R 759587.143826 3.311661e+06 \n", "\n", " surface_x surface_y isHorizontal \n", "0 759587.93444 3.311662e+06 Vertical \n", "1 759587.93444 3.311662e+06 Vertical \n", "2 759587.93444 3.311662e+06 Vertical \n", "3 759587.93444 3.311662e+06 Vertical \n", "4 759587.93444 3.311662e+06 Vertical " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# call the from_df method, fill in the parameters with the column names\n", "my_data = DataSource.from_df(df, wellId_name='wellId',md_name='md',inc_name='inc',azim_name='azim',\n", " surface_latitude_name='surface_latitude',surface_longitude_name='surface_longitude')\n", "\n", "#view the dict data dataclass object\n", "my_data.data\n", "#create a wellboreTrajectory object\n", "dev_obj = WellboreTrajectory(my_data.data)\n", "#view the object\n", "dev_obj.deviation_survey_obj\n", "#calculate the survey points along the wellbore for the object\n", "dev_obj.calculate_survey_points()\n", "#serialize the data\n", "json_ds = dev_obj.serialize()\n", "\n", "# view the json in a df\n", "json_ds_obj = json.loads(json_ds)\n", "df_min_curve = pd.DataFrame(json_ds_obj)\n", "df_min_curve.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# From CSV" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you have a csv and want to calculate its metadata use the following workflow. Just enter in the column names and calculate its survey points." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimtvde_w_deviationn_s_deviationdlssurface_latitudesurface_longitudelongitude_pointslatitude_pointszone_numberzone_letterx_pointsy_pointssurface_xsurface_yisHorizontal
0well_C0.000.00227.110.0000000.000000e+000.000000e+000.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
1well_C35.000.00227.1135.000000-1.484001e-17-1.378531e-170.00000029.90829447.68852147.68852129.90829438R759587.9344403.311662e+06759587.934443.311662e+06Vertical
2well_C774.810.46227.11774.802052-2.175842e+00-2.021203e+000.06217829.90829447.68852147.68851429.90828938R759587.2712433.311661e+06759587.934443.311662e+06Vertical
3well_C800.000.13163.86799.991684-2.241984e+00-2.117474e+001.31232329.90829447.68852147.68851429.90828938R759587.2510833.311661e+06759587.934443.311662e+06Vertical
4well_C900.000.57230.43899.989571-2.593878e+00-2.543311e+000.43922129.90829447.68852147.68851229.90828838R759587.1438263.311661e+06759587.934443.311662e+06Vertical
\n", "
" ], "text/plain": [ " wellId md inc azim tvd e_w_deviation n_s_deviation \\\n", "0 well_C 0.00 0.00 227.11 0.000000 0.000000e+00 0.000000e+00 \n", "1 well_C 35.00 0.00 227.11 35.000000 -1.484001e-17 -1.378531e-17 \n", "2 well_C 774.81 0.46 227.11 774.802052 -2.175842e+00 -2.021203e+00 \n", "3 well_C 800.00 0.13 163.86 799.991684 -2.241984e+00 -2.117474e+00 \n", "4 well_C 900.00 0.57 230.43 899.989571 -2.593878e+00 -2.543311e+00 \n", "\n", " dls surface_latitude surface_longitude longitude_points \\\n", "0 0.000000 29.908294 47.688521 47.688521 \n", "1 0.000000 29.908294 47.688521 47.688521 \n", "2 0.062178 29.908294 47.688521 47.688514 \n", "3 1.312323 29.908294 47.688521 47.688514 \n", "4 0.439221 29.908294 47.688521 47.688512 \n", "\n", " latitude_points zone_number zone_letter x_points y_points \\\n", "0 29.908294 38 R 759587.934440 3.311662e+06 \n", "1 29.908294 38 R 759587.934440 3.311662e+06 \n", "2 29.908289 38 R 759587.271243 3.311661e+06 \n", "3 29.908289 38 R 759587.251083 3.311661e+06 \n", "4 29.908288 38 R 759587.143826 3.311661e+06 \n", "\n", " surface_x surface_y isHorizontal \n", "0 759587.93444 3.311662e+06 Vertical \n", "1 759587.93444 3.311662e+06 Vertical \n", "2 759587.93444 3.311662e+06 Vertical \n", "3 759587.93444 3.311662e+06 Vertical \n", "4 759587.93444 3.311662e+06 Vertical " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "csv_path = get_files(path, folders='data', extensions='.csv')\n", "\n", "my_data = DataSource.from_csv(csv_path.items[0], wellId_name='wellId',md_name='md',inc_name='inc',azim_name='azim',\n", " surface_latitude_name='surface_latitude',surface_longitude_name='surface_longitude')\n", "\n", "#view the dict data dataclass object\n", "my_data.data\n", "#create a wellboreTrajectory object\n", "dev_obj = WellboreTrajectory(my_data.data)\n", "#view the object\n", "dev_obj.deviation_survey_obj\n", "#calculate the survey points along the wellbore for the object\n", "dev_obj.calculate_survey_points()\n", "#serialize the data\n", "json_ds = dev_obj.serialize()\n", "\n", "# view the json in a df\n", "json_ds_obj = json.loads(json_ds)\n", "df_min_curve = pd.DataFrame(json_ds_obj)\n", "df_min_curve.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## From CSV with multiple wells" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you have a file with multiple wells appened one after another you can use this simple function to break them up by wellid, run it through welltrajconvert and calculate each wells metadata. You can then convert the list of dicts into a dataframe." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def from_multiple_wells_to_dict(df: DataFrame, wellId_name: Optional[str] = None, md_name: Optional[str] = None,\n", " inc_name: Optional[str] = None, azim_name: Optional[str] = None,\n", " surface_latitude_name: Optional[str] = None,\n", " surface_longitude_name: Optional[str] = None,\n", " surface_x_name: Optional[str] = None,\n", " surface_y_name: Optional[str] = None):\n", " \"\"\"\n", " takes a df of mulitple well deviation surveys in a typical columnar fashion and calculates their survey points.\n", " Then appends them to a list of dicts.\n", "\n", " :parameter: df\n", "\n", " :returns: list of dict\n", " \"\"\"\n", " # group by wellId, ensures this will work with single well or mulitple.\n", " grouped = df.groupby(wellId_name)\n", "\n", " # initialize empty dict and list\n", " #appended_df = pd.DataFrame()\n", " dict_list = []\n", " # loop through groups converting them to the proper dict format\n", " for name, group in grouped:\n", "\n", " group.reset_index(inplace=True, drop=True)\n", "\n", " if surface_latitude_name is not None and surface_longitude_name is not None:\n", " well_obj = DataSource.from_df(group, wellId_name=wellId_name, md_name=md_name,\n", " inc_name=inc_name, azim_name=azim_name,\n", " surface_latitude_name=surface_latitude_name,\n", " surface_longitude_name=surface_longitude_name)\n", "\n", " if surface_x_name is not None and surface_y_name is not None:\n", " well_obj = DataSource.from_df(group, wellId_name=wellId_name, md_name=md_name,\n", " inc_name=inc_name, azim_name=azim_name,\n", " surface_x_name=surface_x_name,\n", " surface_y_name=surface_y_name)\n", "\n", " well_obj = WellboreTrajectory(well_obj.data)\n", " well_obj.calculate_survey_points()\n", " json_ds = well_obj.serialize()\n", " dict_list.append(json_ds)\n", "\n", " res = dict_list\n", " return res" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['well_C' 'well_A' 'well_B']\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimsurface_latitudesurface_longitude
0well_C0.000.00227.1129.90829447.688521
1well_C35.000.00227.1129.90829447.688521
2well_C774.810.46227.1129.90829447.688521
3well_C800.000.13163.8629.90829447.688521
4well_C900.000.57230.4329.90829447.688521
\n", "
" ], "text/plain": [ " wellId md inc azim surface_latitude surface_longitude\n", "0 well_C 0.00 0.00 227.11 29.908294 47.688521\n", "1 well_C 35.00 0.00 227.11 29.908294 47.688521\n", "2 well_C 774.81 0.46 227.11 29.908294 47.688521\n", "3 well_C 800.00 0.13 163.86 29.908294 47.688521\n", "4 well_C 900.00 0.57 230.43 29.908294 47.688521" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# FROM df with mulitple wells\n", "csv_path = get_files(path, folders='data', extensions='.csv')\n", "csv_path.items[1]\n", "\n", "df = pd.read_csv(csv_path.items[1])\n", "# well id unique\n", "print(df['wellId'].unique())\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "# call function, fill in column name params\n", "dicts = from_multiple_wells_to_dict(df,wellId_name='wellId',md_name='md',inc_name='inc',azim_name='azim',\n", " surface_latitude_name='surface_latitude',surface_longitude_name='surface_longitude')\n", "#dicts[:]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def list_of_dicts_to_df(dict_list):\n", " \"\"\"takes a list of dicts and converts to a appended df\"\"\"\n", " appended_df = pd.DataFrame()\n", " for i in dict_list:\n", " json_ds_obj = json.loads(i)\n", " df_well_obj = pd.DataFrame(json_ds_obj)\n", " appended_df = appended_df.append(df_well_obj)\n", " return appended_df" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
wellIdmdincazimtvde_w_deviationn_s_deviationdlssurface_latitudesurface_longitudelongitude_pointslatitude_pointszone_numberzone_letterx_pointsy_pointssurface_xsurface_yisHorizontal
0well_A0.00000.00227.110.0000000.000000e+000.000000e+000.00000029.90829447.68852147.68852129.90829438R759587.9325863.311662e+06759587.9325863.311662e+06Vertical
1well_A36.75000.00227.1136.750000-1.558201e-17-1.447458e-170.00000029.90829447.68852147.68852129.90829438R759587.9325863.311662e+06759587.9325863.311662e+06Vertical
2well_A813.55050.46227.11813.542155-2.284634e+00-2.122263e+000.05921729.90829447.68852147.68851329.90828938R759587.2362303.311661e+06759587.9325863.311662e+06Vertical
3well_A840.00000.13163.86839.991268-2.354083e+00-2.223348e+001.24983229.90829447.68852147.68851329.90828938R759587.2150623.311661e+06759587.9325863.311662e+06Vertical
4well_A945.00000.57230.43944.989049-2.723571e+00-2.670477e+000.41830629.90829447.68852147.68851229.90828738R759587.1024423.311661e+06759587.9325863.311662e+06Vertical
\n", "
" ], "text/plain": [ " wellId md inc azim tvd e_w_deviation n_s_deviation \\\n", "0 well_A 0.0000 0.00 227.11 0.000000 0.000000e+00 0.000000e+00 \n", "1 well_A 36.7500 0.00 227.11 36.750000 -1.558201e-17 -1.447458e-17 \n", "2 well_A 813.5505 0.46 227.11 813.542155 -2.284634e+00 -2.122263e+00 \n", "3 well_A 840.0000 0.13 163.86 839.991268 -2.354083e+00 -2.223348e+00 \n", "4 well_A 945.0000 0.57 230.43 944.989049 -2.723571e+00 -2.670477e+00 \n", "\n", " dls surface_latitude surface_longitude longitude_points \\\n", "0 0.000000 29.908294 47.688521 47.688521 \n", "1 0.000000 29.908294 47.688521 47.688521 \n", "2 0.059217 29.908294 47.688521 47.688513 \n", "3 1.249832 29.908294 47.688521 47.688513 \n", "4 0.418306 29.908294 47.688521 47.688512 \n", "\n", " latitude_points zone_number zone_letter x_points y_points \\\n", "0 29.908294 38 R 759587.932586 3.311662e+06 \n", "1 29.908294 38 R 759587.932586 3.311662e+06 \n", "2 29.908289 38 R 759587.236230 3.311661e+06 \n", "3 29.908289 38 R 759587.215062 3.311661e+06 \n", "4 29.908287 38 R 759587.102442 3.311661e+06 \n", "\n", " surface_x surface_y isHorizontal \n", "0 759587.932586 3.311662e+06 Vertical \n", "1 759587.932586 3.311662e+06 Vertical \n", "2 759587.932586 3.311662e+06 Vertical \n", "3 759587.932586 3.311662e+06 Vertical \n", "4 759587.932586 3.311662e+06 Vertical " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# convert a list of dicts into a df\n", "df = list_of_dicts_to_df(dicts)\n", "df.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }